package cn.edu.mju.cooprateflat.module.system.controller;

import cn.edu.mju.cooprateflat.common.ManageBaseController;
import com.jfinal.captcha.Captcha;
import com.jfinal.captcha.CaptchaCache;
import com.jfinal.captcha.CaptchaManager;
import com.jfinal.captcha.CaptchaRender;
import com.jfinal.core.Path;
import com.jfinal.kit.LogKit;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import com.jfinal.render.RenderException;
import com.jfinal.render.RenderManager;
import sun.plugin2.applet.ManagerCache;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Map;

@Path("/manage")
public class LoginController extends ManageBaseController {
    public void captche() {
        renderCaptcha();
    }

    public void doLogin(){
        Ret ret = null;
        String loginName = (String)params("loginName");
        String loginPwd = (String)params("loginPwd");
        String code = (String)params("code");
        if(StrKit.notBlank(loginName,loginPwd,code)){
            if(this.validateCaptcha("code")){
                ret = Ret.ok();
            }else {
                ret = Ret.fail("msg","验证码错误！");
            }
        }else{
            ret = Ret.fail();
        }
        renderJson(ret);
    }

}
